package action.admin.feedback;

import beans.FeedBackBean;
import dao.FeedBackDAO;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "updateFeedBack", urlPatterns = {"/updateFeedBack"})
public class updateFeedBack extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String feedback_id = request.getParameter("feedback_id");
        String acc_id = request.getParameter("acc_id");
        String question = request.getParameter("question");
        String answer = request.getParameter("answer");
        String class_id = request.getParameter("class_id");
        FeedBackBean FBbean = new FeedBackBean();
        FBbean.setFeedback_id(feedback_id);
        FBbean.setAcc_id(acc_id);
        FBbean.setQuestion(question);
        FBbean.setAnswer(answer);
        FBbean.setClass_id(class_id);
        FeedBackDAO fbDAO = new FeedBackDAO();
        String msg = "";
        String error = "";
        if (fbDAO.updateFeedBack(FBbean)) {
            msg = "Update  answer successfull !";
            request.setAttribute("msg", msg);
            RequestDispatcher rd = request.getRequestDispatcher("index.jsp?page=feedback");
            rd.forward(request, response);
        } else {
            error = "Update  answer error !";
            request.setAttribute("error", error);
            request.setAttribute("feedback_id", feedback_id);
            request.setAttribute("acc_id", acc_id);
            request.setAttribute("question", question);
            request.setAttribute("answer", answer);
            request.setAttribute("class_id", class_id);
            RequestDispatcher rd = request.getRequestDispatcher("index.jsp?page=update_FeedBack");
            rd.forward(request, response);
        }

    }
}
